package com.family168.leona.domain;

import java.io.Serializable;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.family168.core.tree.LongTreeNode;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;


/**
 * Dept generated by Lingo.
 *
 * @author Lingo
 * @since 2007年08月18日 下午 20时18分45秒0
 */
@Entity
@Table(name = "KNOWLEDGE")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Knowledge extends LongTreeNode<Knowledge> {
    /** * serial. */
    static final long serialVersionUID = 0L;

    /** * id. */
    private Long id;

    /** * parent. */
    private Knowledge parent;

    /** * name. */
    private String name;

    /** * theSort. */
    private Integer theSort;

    /** * descn. */
    private String descn;

    /** * children. */
    private Set<Knowledge> children = new HashSet<Knowledge>(0);

    /** * questions. */
    private Set<Question> questions = new HashSet<Question>(0);

    /** * 构造方法. */
    public Knowledge() {
    }

    /** * @return id. */
    @GenericGenerator(name = "generator", strategy = "increment")
    @Id
    @GeneratedValue(generator = "generator")
    @Column(name = "ID", unique = true, nullable = false)
    public Long getId() {
        return id;
    }

    /** * @param id id. */
    public void setId(Long id) {
        this.id = id;
    }

    /** * @return parent. */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PARENT_ID")
    public Knowledge getParent() {
        return parent;
    }

    /** * @param parent Dept. */
    public void setParent(Knowledge parent) {
        this.parent = parent;
    }

    /** * @return name. */
    @Column(name = "NAME", length = 50)
    public String getName() {
        return name;
    }

    /** * @param name name. */
    public void setName(String name) {
        this.name = name;
    }

    /** * @return theSort. */
    @Column(name = "THE_SORT")
    public Integer getTheSort() {
        return theSort;
    }

    /** * @param theSort Integer. */
    public void setTheSort(Integer theSort) {
        this.theSort = theSort;
    }

    /** * @return descn. */
    @Column(name = "DESCN", length = 200)
    public String getDescn() {
        return descn;
    }

    /** * @param descn descn. */
    public void setDescn(String descn) {
        this.descn = descn;
    }

    /** * @return children. */
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent")
    @OrderBy("theSort asc, id desc")
    public Set<Knowledge> getChildren() {
        return children;
    }

    /** * @param children Set. */
    public void setChildren(Set<Knowledge> children) {
        this.children = children;
    }

    /** * @return questions. */
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "knowledge")
    public Set<Question> getQuestions() {
        return questions;
    }

    /** * @param questions questions. */
    public void setQuestions(Set<Question> questions) {
        this.questions = questions;
    }
}
